package com.yunfei.api.financialCalculator.service;
import com.yunfei.api.financialCalculator.param.YangLaoCalParam;
import com.yunfei.api.financialCalculator.result.YangLaoCalResult;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.enums.ResultStatus;
import com.yunfei.enums.YangLaoCalResultStatus;
import com.yunfei.procedure.YangLaoCalProcedure;
import com.yunfei.utils.jdbc.AiiidbUtil;
import com.yunfei.utils.string.StringUtil;
import org.springframework.core.env.Environment;
public class YangLaoCalService {
    //养老计算器接口
    public static ResultModel cal(YangLaoCalParam param, Environment env){
        ResultModel resultModel=new ResultModel();
        try{
            String birthYearInteger=param.getBirthYearInteger();//出生年份
            String retireAgeInteger=param.getRetireAgeInteger();//退休年龄
            String wantGetAmtNumber=param.getWantGetAmtNumber();//想要获得的钱
            //参数校验
            if(StringUtil.isNullOrEmpty(birthYearInteger)){
                resultModel.setCode(YangLaoCalResultStatus.birthYearInteger.getCode());
                resultModel.setMessage(YangLaoCalResultStatus.birthYearInteger.getMessage());
                return resultModel;
            }
            if(StringUtil.isNullOrEmpty(retireAgeInteger)){
                resultModel.setCode(YangLaoCalResultStatus.retireAgeInteger.getCode());
                resultModel.setMessage(YangLaoCalResultStatus.retireAgeInteger.getMessage());
                return resultModel;
            }
            if(StringUtil.isNullOrEmpty(wantGetAmtNumber)){
                resultModel.setCode(YangLaoCalResultStatus.wantGetAmtNumber.getCode());
                resultModel.setMessage(YangLaoCalResultStatus.wantGetAmtNumber.getMessage());
                return resultModel;
            }
            //调用存储过程
            AiiidbUtil aiiidbUtil=AiiidbUtil.getInstance(env);
            YangLaoCalResult result=new YangLaoCalProcedure().callProcedure(aiiidbUtil,param);
            resultModel.setData(result);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        }catch (Exception e){
            e.printStackTrace();
        }
        return resultModel;
    }
}
